<template>
  <div>
    <!-- 本月上升或下降百分比 -->
    <div></div>
    <div :class="className" :style="{height:height,width:width}" />
    <!-- 本月上升或下降数值 -->
    <div></div>
  </div>
  
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
// import resize from './mixins/resize'

// const animationDuration = 6000

export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    clatestcategorytop3: {
      type: Object,
      // 对象或数组默认值必须从一个工厂函数获取
      default: function() {
        return {categoryId: 3,
            value: 300}
      }
    },
    clastcategorytop3: {
      type: Object,
      default: function() {
        return {categoryId: 3,
            value: 300}
      }
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'line' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        // grid: {
        //   top: 10,
        //   left: '2%',
        //   right: '2%',
        //   bottom: '3%',
        //   containLabel: true
        // },
        xAxis: [{
          show:false, // 不显示坐标轴线、坐标轴刻度线和坐标轴上的文字
          axisTick:{
            show:false // 不显示坐标轴刻度线
          },
          axisLine: {
            show: false, // 不显示坐标轴线
          },
          type: 'category',
          data: ['1', '2', '3', '4', '5'],
          axisTick: {
            alignWithLabel: true
          }
          
        }],
        yAxis: [{
          show:false, // 不显示坐标轴线、坐标轴刻度线和坐标轴上的文字
          type: 'value',
          axisTick: {
            show: false
          }
        }],
        series: [{
          name: '当前top',
          type: 'line',
          // stack: 'vistors',
          // barWidth: '60%',
          data: [this.valueMin/8,this.valueMin/2.5,this.clatestcategorytop3.value,this.valueMin/2.5,this.valueMin/8],
          // animationDuration
        }, {
          name: '上月同类',
          type: 'line',
          // stack: 'vistors',
          // barWidth: '60%',
          data: [this.valueMin/8,this.valueMin/2.5, this.clastcategorytop3.value,this.valueMin/2.5,this.valueMin/8],
          // animationDuration
        }]
      })
    }
  },
  computed: {
    valueMin:function() {
      let valueMin = this.clatestcategorytop3.value < this.clastcategorytop3.value ? this.clatestcategorytop3.value : this.clastcategorytop3.value
      console.log(valueMin);
      return valueMin
    }
  }
}
</script>
